<template>
  <div class="app-container">
    <div class="info flex">
      <div class="info_content">
        <div class="flex">
          <div class="info_item">
            {{ $courseName ? $courseName : "课程" }}：李四
          </div>
          <div class="info_item">主讲老师：20185</div>
          <div class="info_item">成绩：XX</div>
        </div>
      </div>
    </div>

    <el-table v-loading="loading" :data="postList">
      <el-table-column label="类型" align="center" prop="postId" />
      <el-table-column label="学分" align="center" prop="postCode" />
      <el-table-column :label="`${$hourAmount?$hourAmount:'课时量'}(周)`" align="center" prop="postName" />
      <el-table-column
        :label="`${$gradeName ? $gradeName : '班级'}`"
        align="center"
        prop="postSort"
      />
      <el-table-column label="成绩" align="center" prop="postSort" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-preventReClick
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate(scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改岗位对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :title="title"
      :visible.sync="open"
      width="800px"
      append-to-body
    >
      <div class="info flex">
        <div class="info_content">
          <div class="flex">
            <div class="info_item">
              {{ $gradeName ? $gradeName : "班级" }}：李四
            </div>
            <div class="info_item">
              {{ $courseName ? $courseName : "课程" }}:
            </div>
            <div class="info_item">主讲老师：XX</div>
          </div>
          <div class="flex">
            <div class="info_item" style="width: 180px">类型：李四</div>
            <div class="info_item" style="width: 180px">学分：20185</div>
            <div class="info_item" style="width: 180px">{{ $hourAmount?$hourAmount:'课时量' }}(周)：XX</div>
            <div class="info_item" style="width: 180px">成绩：XX</div>
          </div>
        </div>
      </div>

      <el-table v-loading="loading" :data="postList">
        <el-table-column label="学生" align="center" prop="postId" />
        <el-table-column label="成绩" align="center" prop="postCode" />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button v-preventReClick @click="cancel">取 消</el-button>
        <el-button v-preventReClick type="primary" @click="submitForm"
          >确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
//TODO 只写了全局模板
import {
  listPost,
  getPost,
  delPost,
  addPost,
  updatePost,
} from "@/api/system/post";
import { listPost_class } from "@/api/schoolOrganization/organization";
import { listPost_course } from "@/api/course/course";
export default {
  name: "Post",
  dicts: ["sys_normal_disable"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        courseName: undefined,
        studentName: undefined,
        classId: undefined,
        type: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
    this.getInfo();
  },
  methods: {
    getInfo() {},
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listPost(this.queryParams).then((response) => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
        postName: undefined,
        postSort: 0,
        status: "0",
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const postId = row.postId || this.ids;
      getPost(postId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "编辑";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.postId != undefined) {
            updatePost(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPost(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleDiaListDelete(row) {
      const postIds = row.postId || this.ids;
      this.$modal
        .confirm("确定删除")
        .then(function () {
          return delPost(postIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="scss" scoped>
.info {
  margin: 10px 0 10px 0;
  &_avatar {
    width: 100px;
    height: 140px;
  }
  &_content {
    margin: 0;
    .info_item {
      width: 240px;
      margin-bottom: 20px;
      font-size: 14px;
      font-weight: 400;
      color: rgba(96, 98, 102, 1);
    }
  }
}
</style>
